// xc_lshop/shop/activity/actall/allactlist.js
var actbill = require('../../model/activity_list')
var actprobill = require('../../../../xc/model/pro_contents')

Page({
  mixins: [require('../../../../xc/mixins/basicMixin')],

  /**
   * 页面的初始数据
   */
  data: {
    actempty:true,
    navid: 1,
    nav: [],
    selected:{}
  },

  xcloaddata: function (options, config) {
    console.log(this.data)
    if(options.itype){
      var itype=options.itype
    }else{
      var itype=0
    }
    this.getconfig(config)
    this.getall(itype)
  },
  // 注册
  login() {
    var app = getApp()
    var that = this
    app.xc_sys_config.authop.oppower("login").then(function (res) {
      that.setData({
        "member": app.globalData.member
      })
    })
  },
  afterlogin: function (options, config, userinfo) {
    if (userinfo.memberinfo) {
      this.setData({
        member: userinfo
      })
    } else {
      this.login()
    }
  },
  attrchoose: function (e) {
    var choosed = e.detail;
      var selected=this.data.selected;
      selected[choosed.proid]=e.detail
      this.setData({
        selected: selected
      })
  },
  getconfig(config){
    var that = this;
    var updatedata = {};
    if (config.prothem) {
      // if (config.prothem.themcolor) {
      //   var themconfig = config.prothem.themcolor.config;
      //   updatedata['themconfig'] = themconfig
      // }
      if (config.prothem.popup) {
        var popconfig = config.prothem.popup.proconfig;
        var popCustomStyle = config.prothem.popup.customStyle;
        updatedata['popconfig'] = popconfig
        updatedata['popCustomStyle'] = popCustomStyle
      }
    }
    that.setData(updatedata)
  },
  buyop: function (ev) {
    //活动未开始/结束/下架不能购买 达到上限
   if ((!this.data.activity) || this.data.activity.actstatus != 1) {
     return;
   }
   if (this.data.member && !this.data.member.memberinfo) {
     this.login();
    //  return;
   }
   var dataset = ev.currentTarget.dataset



   var that = this
   var option = "";
   if (this.data.activity.id) {
     option = {
       aid: this.data.activity.id,
       atype: this.data.activity.itype
     }
   }
   console.log("dataset.id")
   console.log(dataset.id)
   console.log(that.data.selected[dataset.id])
   console.log(option)

   actprobill.showattrchose(that,dataset.id,  that.data.selected[dataset.id],3, option)
 },
 changenav(e){
    var activityid=e.currentTarget.dataset.activityid;
    this.setData({
      navid:activityid
    })
    this.getmodel(activityid)
 },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },
  getall(itype) {
    var that = this;
    actbill.getall(itype).then(function (res) {
  
      if (res['status'] == 1) {
        var obj=res['obj'];
        if(obj.length>0){
          var navid=res['obj'][0]['id'];
          that.setData({
            actempty:false,
            navid:navid,
            nav: res['obj']
          })
          that.getmodel(navid)
        }
      }
    })
  },
  //获取活动数据 actstatus-2下架 -1未开始 1进行中 2已结束
  getmodel(id){
    var that=this;
    actbill.getmodel(id).then(function(res){
      if(res['status']==1){
        console.log(res['obj'])
         that.setData({
           activitypros:res['obj']['pros'],
           activity:res['obj']
         })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

})